using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Web.UI;
using PickGold.Charting.Utilities;

namespace PickGold.Charting
{
	internal class ChartImage : ChartPicture
	{
		private int _compression;
		private object _dataSource;
		internal bool boundToDataSource;
		private ChartImageType imageType;

		internal ChartImage(IServiceContainer container)
			: base(container)
		{
			this.imageType = ChartImageType.Png;
		}

		internal void AlignDataPointsByAxisLabel(bool sortAxisLabels, PointSortOrder sortingOrder)
		{
			foreach (ChartArea area in base.ChartAreas)
			{
				if (area.Visible)
				{
					ArrayList seriesList = new ArrayList();
					ArrayList list2 = new ArrayList();
					foreach (Series series in base.Common.Chart.Series)
					{
						if ((series.ChartArea == area.Name) && (series.XSubAxisName.Length == 0))
						{
							if (series.XAxisType == AxisType.Primary)
							{
								seriesList.Add(series);
							}
							else
							{
								list2.Add(series);
							}
						}
					}
					this.AlignDataPointsByAxisLabel(seriesList, sortAxisLabels, sortingOrder);
					this.AlignDataPointsByAxisLabel(list2, sortAxisLabels, sortingOrder);
				}
			}
		}

		internal void AlignDataPointsByAxisLabel(ArrayList seriesList, bool sortAxisLabels, PointSortOrder sortingOrder)
		{
			if (seriesList.Count != 0)
			{
				bool flag = true;
				bool flag2 = true;
				ArrayList list = new ArrayList();
				foreach (Series series in seriesList)
				{
					ArrayList list2 = new ArrayList();
					foreach (DataPoint point in series.Points)
					{
						if (!series.IsXValueIndexed && (point.XValue != 0.0))
						{
							flag = false;
							break;
						}
						if (point.AxisLabel.Length == 0)
						{
							flag2 = false;
							break;
						}
						if (list2.Contains(point.AxisLabel))
						{
							flag2 = false;
							break;
						}
						if (!list.Contains(point.AxisLabel))
						{
							list.Add(point.AxisLabel);
						}
						list2.Add(point.AxisLabel);
					}
				}
				if (sortAxisLabels)
				{
					list.Sort();
					if (sortingOrder == PointSortOrder.Descending)
					{
						list.Reverse();
					}
				}
				if (!flag)
				{
					throw new InvalidOperationException(SR.ExceptionChartDataPointsAlignmentFaild);
				}
				if (!flag2)
				{
					throw new InvalidOperationException(SR.ExceptionChartDataPointsAlignmentFaildAxisLabelsInvalid);
				}
				if (flag && flag2)
				{
					foreach (Series series2 in seriesList)
					{
						foreach (DataPoint point2 in series2.Points)
						{
							point2.XValue = list.IndexOf(point2.AxisLabel) + 1;
						}
						series2.Sort(PointSortOrder.Ascending, "X");
					}
					foreach (Series series3 in seriesList)
					{
						series3.IsXValueIndexed = true;
						for (int i = 0; i < list.Count; i++)
						{
							if ((i >= series3.Points.Count) || (series3.Points[i].XValue != (i + 1)))
							{
								DataPoint item = new DataPoint(series3);
								item.AxisLabel = (string)list[i];
								item.XValue = i + 1;
								item.YValues[0] = 0.0;
								item.IsEmpty = true;
								series3.Points.Insert(i, item);
							}
						}
					}
				}
			}
		}

		internal void DataBind()
		{
			this.boundToDataSource = true;
			object dataSource = this.DataSource;
			if (dataSource != null)
			{
				if (dataSource is OleDbDataAdapter)
				{
					dataSource = ((OleDbDataAdapter)dataSource).SelectCommand;
				}
				else if (dataSource is SqlDataAdapter)
				{
					dataSource = ((SqlDataAdapter)dataSource).SelectCommand;
				}
				if ((dataSource is DataSet) && (((DataSet)dataSource).Tables.Count > 0))
				{
					dataSource = ((DataSet)dataSource).DefaultViewManager.CreateDataView(((DataSet)dataSource).Tables[0]);
				}
				else if (dataSource is DataTable)
				{
					dataSource = new DataView((DataTable)dataSource);
				}
				else
				{
					if (dataSource is OleDbCommand)
					{
						OleDbCommand command = (OleDbCommand)dataSource;
						command.Connection.Open();
						OleDbDataReader reader = command.ExecuteReader();
						this.DataBind(reader, null);
						reader.Close();
						command.Connection.Close();
						return;
					}
					if (dataSource is SqlCommand)
					{
						SqlCommand command2 = (SqlCommand)dataSource;
						command2.Connection.Open();
						SqlDataReader reader2 = command2.ExecuteReader();
						this.DataBind(reader2, null);
						reader2.Close();
						command2.Connection.Close();
						return;
					}
					if (dataSource is IList)
					{
						dataSource = dataSource as IList;
					}
					else if (dataSource is IListSource)
					{
						if (((IListSource)dataSource).ContainsListCollection && (((IListSource)dataSource).GetList().Count > 0))
						{
							dataSource = ((IListSource)dataSource).GetList()[0] as IEnumerable;
						}
						else
						{
							dataSource = ((IListSource)dataSource).GetList();
						}
					}
					else
					{
						dataSource = dataSource as IEnumerable;
					}
				}
				this.DataBind(dataSource as IEnumerable, null);
			}
		}

		internal void DataBind(IEnumerable dataSource, ArrayList seriesList)
		{
			if ((dataSource != null) && (base.Common != null))
			{
				if (seriesList == null)
				{
					seriesList = new ArrayList();
					foreach (Series series in base.Common.Chart.Series)
					{
						if (base.Common.Chart.IsDesignMode())
						{
							if (series.YValueMembers.Length > 0)
							{
								seriesList.Add(series);
							}
						}
						else
						{
							seriesList.Add(series);
						}
					}
				}
				foreach (Series series2 in seriesList)
				{
					if ((series2.XValueMember.Length > 0) || (series2.YValueMembers.Length > 0))
					{
						series2.Points.Clear();
					}
				}
				IEnumerator xEnumerator = dataSource.GetEnumerator();
				if (xEnumerator.GetType() != typeof(DbEnumerator))
				{
					try
					{
						xEnumerator.Reset();
					}
					catch (InvalidOperationException)
					{
					}
					catch (NotSupportedException)
					{
					}
				}
				bool flag = true;
				bool flag2 = true;
				do
				{
					flag = xEnumerator.MoveNext();
					foreach (Series series3 in seriesList)
					{
						if ((series3.XValueMember.Length <= 0) && (series3.YValueMembers.Length <= 0))
						{
							continue;
						}
						string[] strArray = null;
						if (series3.YValueMembers.Length > 0)
						{
							strArray = series3.YValueMembers.Replace(",,", "\n").Split(new char[] { ',' });
							for (int i = 0; i < strArray.Length; i++)
							{
								strArray[i] = strArray[i].Replace("\n", ",").Trim();
							}
						}
						if (dataSource is string)
						{
							throw new ArgumentException(SR.ExceptionDataBindYValuesToString, "dataSource");
						}
						if ((strArray == null) || (strArray.GetLength(0) > series3.YValuesPerPoint))
						{
							throw new ArgumentOutOfRangeException("dataSource", SR.ExceptionDataPointYValuesCountMismatch(series3.YValuesPerPoint.ToString(CultureInfo.InvariantCulture)));
						}
						if (flag)
						{
							if (flag2)
							{
								flag2 = false;
								string yField = strArray[0];
								int num2 = 1;
								while ((yField.Length == 0) && (num2 < strArray.Length))
								{
									yField = strArray[num2++];
								}
								DataPointCollection.AutoDetectValuesType(series3, xEnumerator, series3.XValueMember.Trim(), xEnumerator, yField);
							}
							DataPoint dataPoint = new DataPoint(series3);
							bool flag3 = false;
							bool flag4 = false;
							object[] yValue = new object[strArray.Length];
							object xValue = null;
							if (series3.XValueMember.Length > 0)
							{
								xValue = DataPointCollection.ConvertEnumerationItem(xEnumerator.Current, series3.XValueMember.Trim());
								if ((xValue is DBNull) || (xValue == null))
								{
									flag4 = true;
									flag3 = true;
									xValue = 0.0;
								}
							}
							if (strArray.Length == 0)
							{
								yValue[0] = DataPointCollection.ConvertEnumerationItem(xEnumerator.Current, null);
								if ((yValue[0] is DBNull) || (yValue[0] == null))
								{
									flag3 = true;
									yValue[0] = 0.0;
								}
							}
							else
							{
								for (int j = 0; j < strArray.Length; j++)
								{
									if (strArray[j].Length > 0)
									{
										yValue[j] = DataPointCollection.ConvertEnumerationItem(xEnumerator.Current, strArray[j]);
										if ((yValue[j] is DBNull) || (yValue[j] == null))
										{
											flag3 = true;
											yValue[j] = 0.0;
										}
									}
									else
									{
										yValue[j] = ((Series)seriesList[0]).IsYValueDateTime() ? DateTime.Now.Date.ToOADate() : 0.0;
									}
								}
							}
							if (!flag4)
							{
								if (flag3)
								{
									if (xValue != null)
									{
										dataPoint.SetValueXY(xValue, yValue);
									}
									else
									{
										dataPoint.SetValueXY(0, yValue);
									}
									series3.Points.DataPointInit(ref dataPoint);
									dataPoint.IsEmpty = true;
									series3.Points.Add(dataPoint);
								}
								else
								{
									if (xValue != null)
									{
										dataPoint.SetValueXY(xValue, yValue);
									}
									else
									{
										dataPoint.SetValueXY(0, yValue);
									}
									series3.Points.DataPointInit(ref dataPoint);
									series3.Points.Add(dataPoint);
								}
							}
							if (base.Common.Chart.IsDesignMode())
							{
								series3["TempDesignData"] = "true";
							}
						}
					}
				}
				while (flag);
			}
		}

		internal void DataBindCrossTab(IEnumerable dataSource, string seriesGroupByField, string xField, string yFields, string otherFields, bool sort, PointSortOrder sortingOrder)
		{
			if (dataSource == null)
			{
				throw new ArgumentNullException("dataSource", SR.ExceptionDataPointInsertionNoDataSource);
			}
			if (dataSource is string)
			{
				throw new ArgumentException(SR.ExceptionDataBindSeriesToString, "dataSource");
			}
			if (string.IsNullOrEmpty(yFields))
			{
				throw new ArgumentException(SR.ExceptionChartDataPointsInsertionFailedYValuesEmpty, "yFields");
			}
			if (string.IsNullOrEmpty(seriesGroupByField))
			{
				throw new ArgumentException(SR.ExceptionDataBindSeriesGroupByParameterIsEmpty, "seriesGroupByField");
			}
			ArrayList list = new ArrayList();
			ArrayList list2 = new ArrayList();
			string[] strArray = null;
			if (yFields != null)
			{
				strArray = yFields.Replace(",,", "\n").Split(new char[] { ',' });
				for (int i = 0; i < strArray.Length; i++)
				{
					strArray[i] = strArray[i].Replace("\n", ",");
				}
			}
			string[] otherAttributeNames = null;
			string[] otherFieldNames = null;
			string[] otherValueFormat = null;
			DataPointCollection.ParsePointFieldsParameter(otherFields, ref otherAttributeNames, ref otherFieldNames, ref otherValueFormat);
			IEnumerator dataSourceEnumerator = DataPointCollection.GetDataSourceEnumerator(dataSource);
			if (dataSourceEnumerator.GetType() != typeof(DbEnumerator))
			{
				try
				{
					dataSourceEnumerator.Reset();
				}
				catch (NotSupportedException)
				{
				}
				catch (InvalidOperationException)
				{
				}
			}
			bool flag = true;
			object[] yValue = new object[strArray.Length];
			object val = null;
			bool flag2 = true;
			do
			{
				if (flag)
				{
					flag = dataSourceEnumerator.MoveNext();
				}
				if (flag)
				{
					object obj3 = DataPointCollection.ConvertEnumerationItem(dataSourceEnumerator.Current, seriesGroupByField);
					Series series = null;
					int index = list2.IndexOf(obj3);
					if (index >= 0)
					{
						series = (Series)list[index];
					}
					else
					{
						series = new Series();
						series.YValuesPerPoint = strArray.GetLength(0);
						if (list.Count > 0)
						{
							series.XValueType = ((Series)list[0]).XValueType;
							series.autoXValueType = ((Series)list[0]).autoXValueType;
							series.YValueType = ((Series)list[0]).YValueType;
							series.autoYValueType = ((Series)list[0]).autoYValueType;
						}
						string str = obj3 as string;
						if (str != null)
						{
							series.Name = str;
						}
						else
						{
							series.Name = seriesGroupByField + " - " + obj3.ToString();
						}
						list2.Add(obj3);
						list.Add(series);
					}
					if (flag2)
					{
						flag2 = false;
						DataPointCollection.AutoDetectValuesType(series, dataSourceEnumerator, xField, dataSourceEnumerator, strArray[0]);
					}
					DataPoint dataPoint = new DataPoint(series);
					bool flag3 = false;
					if (xField.Length > 0)
					{
						val = DataPointCollection.ConvertEnumerationItem(dataSourceEnumerator.Current, xField);
						if (DataPointCollection.IsEmptyValue(val))
						{
							flag3 = true;
							val = 0.0;
						}
					}
					if (strArray.Length == 0)
					{
						yValue[0] = DataPointCollection.ConvertEnumerationItem(dataSourceEnumerator.Current, null);
						if (DataPointCollection.IsEmptyValue(yValue[0]))
						{
							flag3 = true;
							yValue[0] = 0.0;
						}
					}
					else
					{
						for (int j = 0; j < strArray.Length; j++)
						{
							yValue[j] = DataPointCollection.ConvertEnumerationItem(dataSourceEnumerator.Current, strArray[j]);
							if (DataPointCollection.IsEmptyValue(yValue[j]))
							{
								flag3 = true;
								yValue[j] = 0.0;
							}
						}
					}
					if ((otherAttributeNames != null) && (otherAttributeNames.Length > 0))
					{
						for (int k = 0; k < otherFieldNames.Length; k++)
						{
							object obj4 = DataPointCollection.ConvertEnumerationItem(dataSourceEnumerator.Current, otherFieldNames[k]);
							if (!DataPointCollection.IsEmptyValue(obj4))
							{
								dataPoint.SetPointCustomProperty(obj4, otherAttributeNames[k], otherValueFormat[k]);
							}
						}
					}
					if (flag3)
					{
						if (val != null)
						{
							dataPoint.SetValueXY(val, yValue);
						}
						else
						{
							dataPoint.SetValueXY(0, yValue);
						}
						DataPointCollection.DataPointInit(series, ref dataPoint);
						dataPoint.IsEmpty = true;
						series.Points.Add(dataPoint);
					}
					else
					{
						if (val != null)
						{
							dataPoint.SetValueXY(val, yValue);
						}
						else
						{
							dataPoint.SetValueXY(0, yValue);
						}
						DataPointCollection.DataPointInit(series, ref dataPoint);
						series.Points.Add(dataPoint);
					}
				}
			}
			while (flag);
			if (sort)
			{
				ArrayList list3 = (ArrayList)list2.Clone();
				list2.Sort();
				if (sortingOrder == PointSortOrder.Descending)
				{
					list2.Reverse();
				}
				ArrayList list4 = new ArrayList();
				foreach (object obj5 in list2)
				{
					list4.Add(list[list3.IndexOf(obj5)]);
				}
				list = list4;
			}
			foreach (Series series2 in list)
			{
				base.Common.Chart.Series.Add(series2);
			}
		}

		internal void DataBindTable(IEnumerable dataSource, string xField)
		{
			if (dataSource == null)
			{
				throw new ArgumentNullException("dataSource");
			}
			ArrayList dataSourceMemberNames = GetDataSourceMemberNames(dataSource, true);
			if ((xField != null) && (xField.Length > 0))
			{
				int index = dataSourceMemberNames.IndexOf(xField);
				if (index >= 0)
				{
					dataSourceMemberNames.RemoveAt(index);
				}
				else if ((int.TryParse(xField, NumberStyles.Any, CultureInfo.InvariantCulture, out index) && (index >= 0)) && (index < dataSourceMemberNames.Count))
				{
					dataSourceMemberNames.RemoveAt(index);
				}
			}
			if (dataSourceMemberNames.Count > 0)
			{
				ArrayList seriesList = new ArrayList();
				int num3 = 0;
				foreach (string str in dataSourceMemberNames)
				{
					Series series = new Series(str);
					series.YValueMembers = str;
					series.XValueMember = xField;
					seriesList.Add(series);
					num3++;
				}
				this.DataBind(dataSource, seriesList);
				foreach (Series series2 in seriesList)
				{
					series2.YValueMembers = string.Empty;
					series2.XValueMember = string.Empty;
					base.Common.Chart.Series.Add(series2);
				}
			}
		}

		internal static ArrayList GetDataSourceMemberNames(object dataSource, bool usedForYValue)
		{
			ArrayList list = new ArrayList();
			if (dataSource != null)
			{
				if (dataSource.GetType().GetInterface("IDataSource") != null)
				{
					try
					{
						MethodInfo method = dataSource.GetType().GetMethod("Select");
						if (method != null)
						{
							if (method.GetParameters().Length == 1)
							{
								ConstructorInfo constructor = dataSource.GetType().Assembly.GetType("System.Web.UI.DataSourceSelectArguments", true).GetConstructor(new Type[0]);
								dataSource = method.Invoke(dataSource, new object[] { constructor.Invoke(new object[0]) });
							}
							else
							{
								dataSource = method.Invoke(dataSource, new object[0]);
							}
						}
					}
					catch (TargetException)
					{
					}
					catch (TargetInvocationException)
					{
					}
				}
				DataTable dataTable = null;
				if (dataSource is DataTable)
				{
					dataTable = (DataTable)dataSource;
				}
				else if (dataSource is DataView)
				{
					dataTable = ((DataView)dataSource).Table;
				}
				else if ((dataSource is DataSet) && (((DataSet)dataSource).Tables.Count > 0))
				{
					dataTable = ((DataSet)dataSource).Tables[0];
				}
				else if (dataSource is OleDbDataAdapter)
				{
					dataTable = new DataTable();
					dataTable.Locale = CultureInfo.CurrentCulture;
					dataTable = ((OleDbDataAdapter)dataSource).FillSchema(dataTable, SchemaType.Mapped);
				}
				else if (dataSource is SqlDataAdapter)
				{
					dataTable = new DataTable();
					dataTable.Locale = CultureInfo.CurrentCulture;
					dataTable = ((SqlDataAdapter)dataSource).FillSchema(dataTable, SchemaType.Mapped);
				}
				else if (dataSource is OleDbDataReader)
				{
					for (int i = 0; i < ((OleDbDataReader)dataSource).FieldCount; i++)
					{
						if (!usedForYValue || (((OleDbDataReader)dataSource).GetFieldType(i) != typeof(string)))
						{
							list.Add(((OleDbDataReader)dataSource).GetName(i));
						}
					}
				}
				else if (dataSource is SqlDataReader)
				{
					for (int j = 0; j < ((SqlDataReader)dataSource).FieldCount; j++)
					{
						if (!usedForYValue || (((SqlDataReader)dataSource).GetFieldType(j) != typeof(string)))
						{
							list.Add(((SqlDataReader)dataSource).GetName(j));
						}
					}
				}
				else if (dataSource is OleDbCommand)
				{
					OleDbCommand command = (OleDbCommand)dataSource;
					if (command.Connection != null)
					{
						command.Connection.Open();
						OleDbDataReader reader = command.ExecuteReader();
						if (reader.Read())
						{
							for (int k = 0; k < reader.FieldCount; k++)
							{
								if (!usedForYValue || (reader.GetFieldType(k) != typeof(string)))
								{
									list.Add(reader.GetName(k));
								}
							}
						}
						reader.Close();
						command.Connection.Close();
					}
				}
				else if (dataSource is SqlCommand)
				{
					SqlCommand command2 = (SqlCommand)dataSource;
					if (command2.Connection != null)
					{
						command2.Connection.Open();
						SqlDataReader reader2 = command2.ExecuteReader();
						if (reader2.Read())
						{
							for (int m = 0; m < reader2.FieldCount; m++)
							{
								if (!usedForYValue || (reader2.GetFieldType(m) != typeof(string)))
								{
									list.Add(reader2.GetName(m));
								}
							}
						}
						reader2.Close();
						command2.Connection.Close();
					}
				}
				if (dataTable != null)
				{
					foreach (DataColumn column in dataTable.Columns)
					{
						if (!usedForYValue || (column.DataType != typeof(string)))
						{
							list.Add(column.ColumnName);
						}
					}
				}
				else if ((list.Count == 0) && (dataSource is ITypedList))
				{
					foreach (PropertyDescriptor descriptor in ((ITypedList)dataSource).GetItemProperties(null))
					{
						if (!usedForYValue || (descriptor.PropertyType != typeof(string)))
						{
							list.Add(descriptor.Name);
						}
					}
				}
				else if ((list.Count == 0) && (dataSource is IEnumerable))
				{
					IEnumerator enumerator = ((IEnumerable)dataSource).GetEnumerator();
					enumerator.Reset();
					enumerator.MoveNext();
					foreach (PropertyDescriptor descriptor2 in TypeDescriptor.GetProperties(enumerator.Current))
					{
						if (!usedForYValue || (descriptor2.PropertyType != typeof(string)))
						{
							list.Add(descriptor2.Name);
						}
					}
				}
				if (list.Count == 0)
				{
					list.Add("0");
				}
			}
			return list;
		}

		public Bitmap GetImage()
		{
			return this.GetImage(96f);
		}

		public Bitmap GetImage(float resolution)
		{
			Bitmap image = null;
			Color backColor;
			while (image == null)
			{
				var flag = true;
				try
				{
					image = new Bitmap(base.Width, base.Height);
					image.SetResolution(resolution, resolution);
					flag = false;
				}
				catch (ArgumentException)
				{
					flag = true;
				}
				catch (OverflowException)
				{
					flag = true;
				}
				catch (InvalidOperationException)
				{
					flag = true;
				}
				catch (ExternalException)
				{
					flag = true;
				}
				if (flag)
				{
					image = null;
					var num = Math.Max(resolution / 2f, 96f);
					base.Width = (int)Math.Ceiling(base.Width * num / resolution);
					base.Height = (int)Math.Ceiling(base.Height * num / resolution);
					resolution = num;
				}
			}
			var graph = Graphics.FromImage(image);
			if (base.BackColor != Color.Empty)
				backColor = base.BackColor;
			else
				backColor = Color.White;
			var pen = new Pen(backColor);
			graph.DrawRectangle(pen, 0, 0, base.Width, base.Height);
			pen.Dispose();
			base.Paint(graph, false);
			graph.Dispose();
			return image;
		}

		internal static bool IsValidDataSource(object dataSource)
		{
			if ((dataSource == null) || (((!(dataSource is IEnumerable) && !(dataSource is DataSet)) && (!(dataSource is DataView) && !(dataSource is DataTable))) && ((!(dataSource is OleDbCommand) && !(dataSource is SqlCommand)) && ((!(dataSource is OleDbDataAdapter) && !(dataSource is SqlDataAdapter)) && (dataSource.GetType().GetInterface("IDataSource") == null)))))
			{
				return false;
			}
			return true;
		}

		[SecurityCritical]
		[SecurityTreatAsSafe]
		public void SaveIntoMetafile(Stream imageStream, EmfType emfType)
		{
			if (imageStream == null)
				throw new ArgumentNullException("imageStream");

			using (var bitmap = new Bitmap(base.Width, base.Height))
			{
				using (var graphics = Graphics.FromImage(bitmap))
				{
					var zero = IntPtr.Zero;
					try
					{
						new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
						zero = graphics.GetHdc();
						using (var metafile = new Metafile(imageStream, zero, new Rectangle(0, 0, base.Width, base.Height), MetafileFrameUnit.Pixel, emfType))
						{
							using (var graphics2 = Graphics.FromImage(metafile))
							{
								if (base.BorderSkin.SkinStyle != BorderSkinStyle.None)
									graphics2.Clip = new Region(new Rectangle(0, 0, base.Width, base.Height));
								base.ChartGraph.IsMetafile = true;
								base.Paint(graphics2, false);
								base.ChartGraph.IsMetafile = false;
							}
						}
					}
					finally
					{
						if (zero != IntPtr.Zero)
							graphics.ReleaseHdc(zero);
					}
				}//using (var graphics = Graphics.FromImage(bitmap))
			}//using (var bitmap = new Bitmap(base.Width, base.Height))
		}

		[DefaultValue(0)]
		[SRDescription("DescriptionAttributeChartImage_Compression")]
		[Bindable(true)]
		[SRCategory("CategoryAttributeImage")]
		[PersistenceMode(PersistenceMode.Attribute)]
		public int Compression
		{
			get
			{
				return this._compression;
			}
			set
			{
				if ((value < 0) || (value > 100))
				{
					throw new ArgumentOutOfRangeException("value", SR.ExceptionChartCompressionInvalid);
				}
				this._compression = value;
			}
		}

		[SRCategory("CategoryAttributeData")]
		[Bindable(true)]
		[SRDescription("DescriptionAttributeDataSource")]
		[DefaultValue(null)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[SerializationVisibility(SerializationVisibility.Hidden)]
		public object DataSource
		{
			get
			{
				return this._dataSource;
			}
			set
			{
				if (this._dataSource != value)
				{
					this._dataSource = value;
					this.boundToDataSource = false;
				}
			}
		}

		[SRDescription("DescriptionAttributeImageType")]
		[PersistenceMode(PersistenceMode.Attribute)]
		[Bindable(true)]
		[DefaultValue(2)]
		[SRCategory("CategoryAttributeImage")]
		public ChartImageType ImageType
		{
			get
			{
				return this.imageType;
			}
			set
			{
				this.imageType = value;
			}
		}
	}
}

